pkgname=firmware-xiaomi-nabu
pkgver=20241112
pkgrel=0
pkgdesc="Firmware for Xiaomi Pad 5"
subpackages="
	$pkgname-adreno
	$pkgname-adsp
	$pkgname-cdsp
	$pkgname-cirrus
	$pkgname-modem
	$pkgname-venus
	$pkgname-wlan
	$pkgname-touchscreen
	$pkgname-hexagonfs
	$pkgname-slpi
	"
url="https://gitlab.postmarketos.org/panpanpanpan/nabu-firmware"
arch="aarch64"
license="proprietary"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
_commit="b17a3ce0f08871f1c4553351b2f64b2c6969cd5c"
source="https://gitlab.postmarketos.org/panpanpanpan/nabu-firmware/-/archive/$_commit/nabu-firmware-main.tar.gz"
builddir="$srcdir/nabu-firmware-$_commit"

package() {
	#parent package is empty
	mkdir -p "$pkgdir"
}

adreno() {
	pkgdesc="Xiaomi Pad 5 adreno firmware"
	install -Dm644 "$builddir"/a630_sqe.fw -t \
		"$subpkgdir/lib/firmware/qcom/"
	install -Dm644 "$builddir"/a640_gmu.bin -t \
		"$subpkgdir/lib/firmware/qcom/"
	install -Dm644 "$builddir"/a640_zap.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
}

adsp() {
	pkgdesc="Xiaomi Pad 5 adsp firmware"
	install -Dm644 "$builddir"/adsp.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
}

cdsp() {
	pkgdesc="Xiaomi Pad 5 cdsp firmware"
	install -Dm644 "$builddir"/cdsp.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
}

cirrus() {
	pkgdesc="Xiaomi Pad 5 cirrus firmware"
	install -Dm644 "$builddir"/cs35l41* -t \
		"$subpkgdir/lib/firmware/cirrus/"
}

modem() {
	pkgdesc="Xiaomi Pad 5 modem firmware"
	# cp because of the modem_pr directory
	mkdir -p "$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
	cp -r "$builddir"/modem* \
		"$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
	find "$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"	\
		-type f -exec chmod 0644 {} \;
}

venus() {
	pkgdesc="Xiaomi Pad 5 venus firmware"
	install -Dm644 "$builddir"/venus.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
}

wlan() {
	pkgdesc="Xiaomi Pad 5 wlan firmware"
	depends="linux-firmware-ath10k"
	install -Dm644 "$builddir"/wlanmdsp.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
}

touchscreen() {
	pkgdesc="Xiaomi Pad 5 touchscreen firmware"
	install -Dm644 "$builddir"/novatek_nt36523_fw.bin -t \
		"$subpkgdir/lib/firmware/novatek/"
}

slpi() {
	pkgdesc="Xiaomi Pad 5 slpi firmware"
	install -Dm644 "$builddir"/slpi_nb.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8150/xiaomi/nabu/"
}

hexagonfs() {
	pkgdesc="Xiaomi Pad 5 hexagonfs files"
	mkdir -p "$subpkgdir"/usr/share/qcom/sm8150/xiaomi
	cp -r "$builddir"/hexagonfs/ \
		"$subpkgdir"/usr/share/qcom/sm8150/xiaomi/nabu
}

sha512sums="
4cff180e0c765dd8d7c9b643699a685ec1394dbbca6420ca21ae4da005320f9aaade033fa5a348111457c7a141b2abc1112abee06d9d6f14f573ed78344587ac  nabu-firmware-main.tar.gz
"
